package com.hengsu.bitmapqiekuai;

/**
 * 作者：twopai on 2017/4/12.
 * 邮箱：twopai@hotmail.com
 */
import java.util.ArrayList;
        import java.util.List;

        import android.graphics.Bitmap;

public class BitmapCutUtils {

    public static List<ImagePiece> split(Bitmap bitmap, int xPiece, int yPiece) {

        List<ImagePiece> pieces = new ArrayList<ImagePiece>();
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        /*int pieceWidth = width / 3;
        int pieceHeight = height / 3;
        for (int i = 0; i < yPiece; i++) {
            for (int j = 0; j < xPiece; j++) {
                ImagePiece piece = new ImagePiece();
                piece.index = j + i * xPiece;
                int xValue = j * pieceWidth;
                int yValue = i * pieceHeight;
                piece.bitmap = Bitmap.createBitmap(bitmap, xValue, yValue,
                        pieceWidth, pieceHeight);
                pieces.add(piece);
            }
        }*/
        ImagePiece piece = null;

        for (int i = 1; i < 3; i++) {
            if (i == 1) {//创建左边的图片
                piece=new ImagePiece();
                piece.bitmap = Bitmap.createBitmap(bitmap, 0, 0,
                        width/2, height);
                pieces.add(piece);
            }else {//创建右边的图片
                piece=new ImagePiece();
                piece.bitmap = Bitmap.createBitmap(bitmap, width/2, 0,
                        width/2, height);
                pieces.add(piece);
            }
        }

        return pieces;
    }

}